class Solution:
    def minimumLength(self, s: str) -> int:
        i = 0
        j = len(s)-1
        char =''
        while i <=j:
            if i == j:
                return 1
            char = s[i]
            # 头向前
            if s[i] == s[j]:

                while s[i] == char and i <j:

                    i+=1
                    if i == j:
                        return 0
                while s[j] == char and i <j:
                    j-=1

            else:
                print(s[i:j])
                return j - i+1

        return 0

    #总结一下，一上来就应该考虑特殊情况
    def minimumLength1(self, s: str) -> int:
        if len(s) == 1:
            return 1
        if len(s) == 2:
            if s[0]!=s[1]:
                return 2
            else:
                return 0
        i ,j = 0,len(s)-1

        while i<j:
            if s[i]==s[j]:
                char = s[i]
                while s[i] == char:
                    i+=1
                    if i == j:
                        return 0
                while s[j] == char:
                    j -= 1
                    if i == j:
                        return 1

            else:
                return j-i +1
        return 0

if __name__ == '__main__':
    s = "bbbbbbbbbbbbbbbbbbbbbbbbbbbabbbbbbbbbbbbbbbccbcbcbccbbabbb"
    solution = Solution()
    val = solution.minimumLength1(s)
    print(val)